package mediainfo.domain;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Informations relatives to a movie file.
 *
 * @author Cedrick Lunven (@clunven)</a>
 */
public class MovieMetadata {

    /**
     * file path.
     */
    private String path;

    /**
     * metadata relative to general file.
     */
    private Map<General, String> generalKeys = new HashMap<>();

    /**
     * metadata relative to audio track.
     */
    private Map<Audio, String> audioKeys = new HashMap<>();

    private List<Map<Audio, String>> audioKeysList = new ArrayList<>();

    /**
     * metadata relative to video track.
     */
    private Map<Video, String> videoKeys = new HashMap<>();

    private List<Map<Video, String>> videoKeysList = new ArrayList<>();

    public MovieMetadata() {
    }

    public MovieMetadata(String filePath) {
        this.path = filePath;
    }

    /**
     * {@inheritDoc}
     */
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("\r\n[KEYS GENERAL]\r\n");
        for (General g : generalKeys.keySet()) {
            sb.append(g).append("=").append(generalKeys.get(g)).append("\r\n");
        }

        sb.append("\r\n[AUDIO]\r\n");
        for (Audio g : audioKeys.keySet()) {
            sb.append(g).append("=").append(audioKeys.get(g)).append("\r\n");
        }

        sb.append("\r\n[VIDEO]\r\n");
        for (Video g : videoKeys.keySet()) {
            sb.append(g).append("=").append(videoKeys.get(g)).append("\r\n");
        }
        return sb.toString();
    }

    /**
     * Getter accessor for attribute 'path'.
     *
     * @return current value of 'path'
     */
    public String getPath() {
        return path;
    }

    /**
     * Setter accessor for attribute 'path'.
     *
     * @param path new value for 'path '
     */
    public void setPath(String path) {
        this.path = path;
    }

    /**
     * Getter accessor for attribute 'generalKeys'.
     *
     * @return current value of 'generalKeys'
     */
    public Map<General, String> getGeneralKeys() {
        return generalKeys;
    }

    /**
     * Return a 'general' value if key exists.
     *
     * @param key target key
     * @return target key
     */
    public String get(General key) {
        return getGeneralKeys().get(key);
    }

    /**
     * Return a 'audit' value if key exists.
     *
     * @param key target key
     * @return target key
     */

    public String get(Audio key) {
        return getAudioKeys().get(key);
    }

    public String getVideoWidth() {
        return get(Video.WIDTH);
    }

    public String getVideoHeight() {
        return get(Video.HEIGHT);
    }

    /**
     * Return a 'video' value if key exists.
     *
     * @param key target key
     * @return target key
     */

    public String get(Video key) {
        return getVideoKeys().get(key);
    }

    /**
     * Setter accessor for attribute 'generalKeys'.
     *
     * @param generalKeys new value for 'generalKeys '
     */
    public void setGeneralKeys(Map<General, String> generalKeys) {
        this.generalKeys = generalKeys;
    }

    public void setGeneralKey(General key, String value) {
        this.generalKeys.put(key, value);
    }

    /**
     * Getter accessor for attribute 'audioKeys'.
     *
     * @return current value of 'audioKeys'
     */
    public Map<Audio, String> getAudioKeys() {
        return audioKeys;
    }

    /**
     * Setter accessor for attribute 'audioKeys'.
     *
     * @param audioKeys new value for 'audioKeys '
     */
    public void setAudioKeys(Map<Audio, String> audioKeys) {
        this.audioKeys = audioKeys;
    }
    public void setAudioKey(Audio key, String value) {
        this.audioKeys.put(key, value);
    }
    /**
     * Getter accessor for attribute 'videoKeys'.
     *
     * @return current value of 'videoKeys'
     */
    public Map<Video, String> getVideoKeys() {
        return videoKeys;
    }

    /**
     * Setter accessor for attribute 'videoKeys'.
     *
     * @param videoKeys new value for 'videoKeys '
     */
    public void setVideoKeys(Map<Video, String> videoKeys) {
        this.videoKeys = videoKeys;
    }
    public void setVideoKey(Video key, String value) {
        this.videoKeys.put(key, value);
    }
    public List<Map<Audio, String>> getAudioKeysList() {
        return audioKeysList;
    }

    public void setAudioKeysList(List<Map<Audio, String>> audioKeysList) {
        this.audioKeysList = audioKeysList;
    }

    public List<Map<Video, String>> getVideoKeysList() {
        return videoKeysList;
    }

    public void setVideoKeysList(List<Map<Video, String>> videoKeysList) {
        this.videoKeysList = videoKeysList;
    }
}
